const http = require('http');
const https = require('https'); // 如果是 HTTPS URL
const fs = require('fs');
const path = require('path');
const crypto = require("crypto");
const querystring = require("querystring");

async function CheckDeviceStatus(host_url, devicetype_, macaddr_) {
    try {
        const url = host_url + "/api/getDevcieStatus";
        console.log('req url: ', url)
        const response = await fetch(url, { // 替换为实际的 API 地址
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
          },
          body: JSON.stringify({
            device_type: devicetype_,
            mac_address: macaddr_,
          }),
        });
        if (!response.ok) {
          throw new Error(`HTTP error! Status: ${response.status}`);
        }
    
        const result = await response.json();
        console.log("result:", result);
        if(result.code === 200) {
          console.log("userid :", result.userId);
          return [result.code, result.status, result.userId, result.uuid, result.registerCode];
        } else {
          console.log("result:", result);
        }
    } catch (error) {
        console.error('Error fetching new version:', error.message);
    }
};

  module.exports = {CheckDeviceStatus};